//
//  KRSportPolyLine.m
//  KRSport
//
//  Created by KaoRny on 17/4/22.
//  Copyright © 2017年 KaoRny. All rights reserved.
//

#import "KRSportPolyLine.h"

@implementation KRSportPolyLine

+ (instancetype)polylineWithSourceLocation:(CLLocation *)source andDestLocation:(CLLocation *)dest{
    
    //构造折线数据对象
    CLLocationCoordinate2D commonPolylineCoords[2];
    //起点  上一次的终点
    commonPolylineCoords[0].latitude = source.coordinate.latitude;
    commonPolylineCoords[0].longitude = source.coordinate.longitude;
    //终点
    commonPolylineCoords[1].latitude = dest.coordinate.latitude;
    commonPolylineCoords[1].longitude = dest.coordinate.longitude;
    
    //构造折线对象
    KRSportPolyLine *commonPolyline = [KRSportPolyLine polylineWithCoordinates:commonPolylineCoords count:2];
    //计算速度
    [commonPolyline calculateSpeedWithSoure:source andDest:dest];
    
    return commonPolyline;
}

//计算速度
- (void)calculateSpeedWithSoure:(CLLocation *)source andDest:(CLLocation *)dest{
    //(起点速度+终点速度) * 0.5  m/s -> km/hour   /1000 * 60 * 60
    _speed = (source.speed + dest.speed) * 0.5 * 3.6;

    //    NSLog(@"%f", _speed);
    // Red 0~1   speed 0~30
    _storkeColor = [UIColor colorWithRed:(_speed * 0.033) green:1 blue:0 alpha:1];
}

@end
